package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.security.annotation.RequiresPermissions;
import com.spzx.product.api.domain.CategoryBrand;
import com.spzx.product.api.domain.vo.CategoryBrandVo;
import com.spzx.product.service.CategoryBrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/categoryBrand")
@Tag(name = "分类品牌后台管理")
public class CategoryBrandController extends BaseController {
    @Resource
    private CategoryBrandService categoryBrandService;

    @Operation(summary = "分页查询分类品牌列表")
    @RequiresPermissions("system:categoryBrand:list")
    @GetMapping("/list")
    public TableDataInfo listInfo(CategoryBrand categoryBrand) {
        startPage();
        List<CategoryBrandVo> categoryBrandVoList = categoryBrandService.categoryBrandInfoList(categoryBrand);
        return getDataTable(categoryBrandVoList);
    }

    @Operation(summary = "查询分类品牌列表")
    @RequiresPermissions("system:categoryBrand:listAll")
    @GetMapping("/listAll")
    public AjaxResult listAll() {
        List<CategoryBrandVo> categoryBrandVoList = categoryBrandService.categoryBrandInfoList(null);
        return success(categoryBrandVoList);
    }

    @Operation(summary = "根据id查询分类品牌详情")
    @GetMapping("/{id}")
    @RequiresPermissions("system:categoryBrand:info")
    public AjaxResult categoryBrandInfoById(@PathVariable Long id) {
        CategoryBrandVo categoryBrandVo = categoryBrandService.getCategoryBrandVoById(id);
        return success(categoryBrandVo);
    }

    @Operation(summary = "批量删除分类品牌")
    @DeleteMapping("/{ids}")
    @RequiresPermissions("system:categoryBrand:remove")
    public AjaxResult deleteCategoryBrandByIds(@PathVariable("ids") List<Long> ids) {
        return toAjax(categoryBrandService.removeBatchByIds(ids));
    }

    @Operation(summary = "新增|修改分类品牌")
    @PostMapping("/saveOrUpdate")
    @RequiresPermissions("system:categoryBrand:saveOrUpdate")
    public AjaxResult saveOrUpdate(@Validated @RequestBody CategoryBrand categoryBrand) {
        categoryBrandService.checkCategoryBrandUnique(categoryBrand);
        return toAjax(categoryBrandService.saveOrUpdate(categoryBrand));
    }
}
